package com.eight.lesson2;

import java.util.ArrayList;
import java.util.List;

public class AppleUtils {

	private AppleUtils() {}
	
	public static List<Apple> filterApples(List<Apple> apples, ApplePredicate p){
		List<Apple> result = new ArrayList<Apple>();
		for(Apple apple : apples) {
			if(p.test(apple)) {
				result.add(apple);
			}
		}
		return result;
	}
	
	public static <T> List<T> filter(List<T> list, Predicate<T> p){
		List<T> result = new ArrayList<T>();
		for(T t : list) {
			if(p.test(t)) {
				result.add(t);
			}
		}
		return result;
	}
	
	public static void prettyPrintApple(List<Apple> apples, AppleFormatter f) {
		for(Apple apple : apples) {
			String formatter = f.accept(apple);
			System.out.println(formatter);
		}
	}
}
